<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
	<nav class="navbar navbar-default">
		<div class="container">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="/">
					<img width="90px" src="/public/img/logo3.png" alt="">
				</a>
			</div>
			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				
				<ul class="nav navbar-nav navbar-right">
					<li class="dropdown">
						<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><img width="20" height="20" src="../public/img/avatar-max-img.png" alt=""> <span class="caret"></span></a>
						<ul class="dropdown-menu">
							<li class="dropdown-current-user">
								<span>当前登入用户：xxx</span>
							</li>
							<li role="separator" class="divider"></li>
							<li><a href="/settings/profile">设置</a></li>
							<li><a href="/logout">退出</a></li>
						</ul>
					</li>
				</ul>
			</div>
			<!-- /.navbar-collapse -->
		</div>
		<!-- /.container-fluid -->
	</nav>
	<div class="row">
		<div class="col-sm-1"></div>
		<div class="col-sm-2">
			<a href="#" class="list-group-item disabled">用户设置</a>
			<a href="/setting/base" class="list-group-item ">基本信息</a>
			<a href="/setting/safe" class="list-group-item active">安全设置</a>
		</div><!-- /.col-sm-4 -->
		<div class="col-sm-4">
			<div class="subhead">
				<h2>修改密码</h2>
			</div>
			<hr>
			<form action="/setting/safe" method="post" id="safe">
				<input type="hidden" name="id" id="safeId" value="{{user._id}}"></input>
				<div class="form-group">
					<label for="exampleInputPassword1">当前密码</label>
					<input type="password" class="form-control" id="Password1" placeholder="" name="" value=""></input>
				</div>
				<div class="form-group">
					<label for="exampleInputPassword1">新的密码</label>
					<input type="password" class="form-control" id="Password2" placeholder="" value=""></input>
				</div>
				<div class="form-group">
					<label for="exampleInputPassword1">确认密码</label>
					<input type="password" class="form-control" id="Password3" placeholder="" value=""></input>
				</div>
				<button type="submit" class="btn btn-success">保存</button>
			</form>
			
		</div><!-- /.col-sm-4 -->
		<div class="col-sm-1"></div>
		<div class="col-sm-3">
			<div class="subhead">
				<h2>注销账号</h2>
				<hr>
			</div>
			<div>
				<p class="alert alert-danger">一旦注销，不可找回，请谨慎操作</p>
				<a href="/del?id={{user._id}}">
					<button class="btn btn-danger">注销</button>
				</a>
			</div>
			<hr>
		</div>
	</div>


</body>
<script src="/public/js/jquery.js"></script>
<script >

	$('#safe').on('submit',function(e){
		e.preventDefault()
		if($('#Password2').val()!=$('#Password3').val()){
			return alert('新密码有误');
			
		}
		var Password1=$('#Password1').val()
		var Password2=$('#Password2').val()
		var id=$('#safeId').val()
		var jsons={oldpassword:Password1,newpassword:Password2,id:id}
	 $.ajax({
	   	url:'/setting/safe',
	   	type:'post',
	   	data:jsons,
	   	dataType:'json',
	   	success:function(data){
	   		var code=data.code
	   		console.log(data)
	   		if(code===0){
	   			window.location.href='/'
	   		}else if(code===500){
	   			window.alert('密码错误')
	   		}
	   	}
	 })
})
</script>
</html>


